package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.entity.AuditStatus;
import com.qf.entity.Train;
import com.qf.form.TrainForm;
import com.qf.service.AuditStatusService;
import com.qf.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/train")
public class TrainController {

    @Autowired
    private TrainService trainService;

    @Autowired
    private AuditStatusService auditStatusService;


    @GetMapping("/list")
    public String list(TrainForm form,
                        @RequestParam(defaultValue = "1")Integer pageNum,
                       @RequestParam(defaultValue = "5")Integer size,
                       Model model){
        PageInfo<Train> pageInfo = trainService.selectAll(form,pageNum, size);
        List<AuditStatus> statusList = auditStatusService.selectAll();
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("statusList",statusList);
        model.addAttribute("trainName",form.getTrainName());
        model.addAttribute("auditStatusId",form.getAuditStatusId());
        model.addAttribute("beginTime",form.getBeginTime());
        model.addAttribute("endTime",form.getEndTime());
        return "/peixun/peixunjihua/list";
    }
}
